/*
 * @Date: 2020-08-26 15:06:54
 * @LastEditors: xujianxing
 * @LastEditTime: 2020-08-26 15:27:32
 * @FilePath: \nili\src\common\anotation\user.ano.ts
 */
import { createParamDecorator, ExecutionContext } from '@nestjs/common';

// 参数装饰器，从 request 中拿到 user 属性,通过给装饰器传入 对象的键来获取对应的值
export const User = createParamDecorator(
  (data: string, ctx: ExecutionContext) => {
    const request = ctx.switchToHttp().getRequest();
    const user = request.body;
    return data ? user && user[data] : user;
  },
);
